<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tiao {
            border: 1px solid #000;
            width: 1000px;
            margin: 100px auto 0;
            height: 50px;
            display: inline-block;
        }

        .tiaoli {
            /* background-color: yellow; */
            width: 0;
            position: relative;
            height: 50px;
            z-index: 1;
            display: inline-block;
        }

        #p1 {
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="tiao" id="dd">
        <div class="tiaoli" id="d1"></div>
        <p id="p1"></p>
    </div>

    <script>
        window.onload = () => {
            // if (d1)
            // let a = d1.style.width
            // console.log(d1.style.width)
            let w = dd.clientWidth;
            // console.log(w)
            let t1 = setInterval(function () {
                d1.style.width = d1.offsetWidth + 1 + "px";
                d1.style.background = "yellow";
                p1.innerHTML = (d1.offsetWidth / w * 100).toFixed(2) + "%";
                if (d1.offsetWidth == w) {
                    clearInterval(t1);
                }
            }, 20)

        }
    </script>
</body>

</html>